package com.ckzp.plugins.layui.tools;


import com.ckzp.core.util.DateUtil;
import com.ckzp.core.util.StringUtil;

import java.util.Date;

/**
 * Created by 51594 on 2022/7/27.
 */
public class FormateLayDate {

    /**
     * @param dates
     * @return
     */
    public static Date[] spdate(String dates) {
        dates = StringUtil.replace(dates, "至", "|");
        dates = StringUtil.replace(dates, "|-|", "|");
        System.out.println(dates);
        String[] ddd = StringUtil.split(dates, "|");
        if (ddd.length == 2) {
            return new Date[]{DateUtil.getDate(ddd[0].trim()), DateUtil.getDate(ddd[1].trim())};
        }
        return null;
    }

    /**
     * @param datestime
     * @return
     */
    public static Date[] spDateTime(String datestime) {
        System.out.println(datestime);
        datestime = StringUtil.replace(datestime, " ", "|");
        datestime = StringUtil.replace(datestime, "|-|", "|");
        System.out.println(datestime);
        String[] ddd = StringUtil.split(datestime, "|");
        if (ddd.length == 2) {
            return new Date[]{DateUtil.getDate(ddd[0]), DateUtil.getDate(ddd[1])};
        }
        return null;
    }

    /**
     * @param dates
     * @return
     */
    public static int getYYYYMMDD(String dates) {
        if (dates == null || dates.length() == 0) {
            return 0;
        } else {
            Date d = DateUtil.getDate(dates);
            return DateUtil.getYYYYMMDD(d);
        }
    }


    /**
     * @param dates
     * @return
     */
    public static String getYYYYMMDDString(String dates) {
        if (dates == null || dates.length() == 0) {
            return null;
        } else {
            Date d = DateUtil.getDate(dates);
            return String.valueOf(DateUtil.getYYYYMMDD(d));
        }
    }


    /**
     * @param dates
     * @return
     */
    public static int getYYYYMM(String dates) {
        Date d = DateUtil.getDate(dates);
        return DateUtil.getYYYYMM(d);
    }

    public static void main(String[] arg) {
        System.out.println(FormateLayDate.spdate("2020-03-13 - 2020-03-13"));
    }

}
